#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2025 Huawei Technologies Co., Ltd. All rights reserved.

from ansible.module_utils.basic import AnsibleModule

from openubmc_ansible.openubmc_logger import report
from openubmc_ansible.openubmc_logger import log
from openubmc_ansible.openubmc_redfish_api.api_power_manager import get_power_status
from openubmc_ansible.openubmc_redfish_api.redfish_base import BmcBaseConnect
from openubmc_ansible.utils import is_support_server
from openubmc_ansible.utils import ansible_bmc_run_module
from openubmc_ansible.utils import SERVERTYPE


ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}

DOCUMENTATION = """
module: openubmc_get_power_status
short_description: get openubmc power info
version_added: "2.5.0"
description: get openubmc power info
options:
  openubmc_ip:
    required: true
    default: None
    description:
      - openUBMC IP address
  openubmc_user:
    required: true
    default: None
    description:
      - openUBMC user name used for authentication
  openubmc_pswd:
    required: true
    default:
    description:
      - openUBMC user password used for authentication

"""
EXAMPLES = r"""
 - name:  get server power status
    openubmc_get_power_status :
      openubmc_ip: "{{ openubmc_ip }}"
      openubmc_user: "{{ openubmc_user }}"
      openubmc_pswd: "{{ openubmc_pswd }}"
"""

RETURNS = """

"""


def openubmc_get_power_status_module(module):
    """
    Function:

    Args:
              ansible_module       (class):

    Returns:
        ret = {"result": False, "msg": 'not run get power status yet'}
    Raises:
        Exception
    Examples:

    Author: xwh
    Date: 2019/10/9 20:30
    """
    with BmcBaseConnect(module.params, log, report) as openubmc:
        ret = is_support_server(openubmc, SERVERTYPE)
        if ret['result']:
            ret = get_power_status(openubmc)
    return ret


def main():
    module = AnsibleModule(
        argument_spec={
            "openubmc_ip": {"required": True, "type": 'str'},
            "openubmc_user": {"required": True, "type": 'str'},
            "openubmc_pswd": {"required": True, "type": 'str', "no_log": True},

        },
        supports_check_mode=False)
    ansible_bmc_run_module(openubmc_get_power_status_module, module, log, report)


if __name__ == '__main__':
    main()
